#ifndef SPATIALINDEX_H
#define SPATIALINDEX_H
#include <GL/glew.h>
#ifdef MACOS
#include <glut.h>
#else
#include <GL/glut.h>
#endif
//#include <vcg/simplex/vertex/base.h>
#include <vcg/simplex/face/base.h>
#include <vcg/complex/trimesh/base.h>
#include <vcg/complex/trimesh/update/bounding.h>
#include <vcg/complex/trimesh/update/normal.h>
#include <vcg/complex/trimesh/create/platonic.h>
#include <vcg/space/color4.h>
//#include <wrap/io_trimesh/import.h>
#include <wrap/gl/trimesh.h>
#include <wrap/gui/trackball.h>
#include "Cluster.h"
#include "expand.h"
#include "DataStructure.h"
#include "math.h"
#include "minSphere.h"
#include "vcg/complex/trimesh/base.h"

//class Expander; //altrimenti non mi faceva dichiarare expand all'interno della classe SpatialIndex
namespace Extension{
    class SpatialIndex
    {
    private:
        priority_queue<Cluster> priorityQueue;
        vector<vector<Cluster> > clusters;
        int level;
        CMesh::PerVertexAttributeHandle<Cluster*> enclosingCluster;
        Expander * expand ;

    public:
        SpatialIndex(CMesh *mesh);
        void build (CMesh *mesh,int n);
        vector<Cluster> base (CMesh *mesh);
        vector<Cluster> step (vector<Cluster> level);
        priority_queue<Cluster> create (vector<Cluster> level);
        vector<Cluster> select (priority_queue<Cluster> myQueue);
        vector<Cluster> link(vector<Cluster> level);
        vector<Cluster> miniball(vector<Cluster> level);
        vector<CVertex> query(CVertex v, float radius);

    private:
        double distance(Point3<float> p1,Point3d p2);
        void max (CVertex *v, int max, vector<CVertex*> *vv);
        CMesh *mesh;
        vcg::GlTrimesh<CMesh> wrap;
    };
}

//vector<vector<Cluster>> topology_index;

#endif // SPATIALINDEX_H
